package com.eastday;


import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;

import org.htmlparser.util.ParserException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.xml.sax.SAXException;

import com.eastday.biz.ParseHtmlBiz;
import com.eastday.biz.ParseXmlConfigBiz;
import com.eastday.model.SysConfigModel;
import com.eastday.model.UrlConfigModel;

public class HtmlProcess {

	private SysConfigModel sysConfigModel;
	private List<UrlConfigModel> urlConfigModelList;
	private ApplicationContext context;
	private ParseXmlConfigBiz parseXmlConfigBiz;
	private ParseHtmlBiz parseHtmlBiz;
	
	public HtmlProcess(){
		this.init();
	}
	
	private void init(){
		context = new ClassPathXmlApplicationContext("beans.xml");
		parseXmlConfigBiz = (ParseXmlConfigBiz)context.getBean("parseXmlConfigBiz");
		parseHtmlBiz      = (ParseHtmlBiz)context.getBean("parseHtmlBiz");
		try {
			sysConfigModel = parseXmlConfigBiz.parseSysConfig();
			urlConfigModelList = parseXmlConfigBiz.parseUrlConfig();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public SysConfigModel getSysConfigModel() {
		return sysConfigModel;
	}

	public void setSysConfigModel(SysConfigModel sysConfigModel) {
		this.sysConfigModel = sysConfigModel;
	}
	
	public List<UrlConfigModel> getUrlConfigModelList() {
		return urlConfigModelList;
	}

	public void setUrlConfigModelList(List<UrlConfigModel> urlConfigModelList) {
		this.urlConfigModelList = urlConfigModelList;
	}

	public void htmlprocess(){
		for(UrlConfigModel urlConfigModel:urlConfigModelList){
			String url = urlConfigModel.getUrl();
			try {
				List<String> htmlPageLinkList = parseHtmlBiz.parseHtmlPageLink(url,sysConfigModel.getDivid());
				for(String pagelink:htmlPageLinkList){
					System.out.println(pagelink);
				}
			} catch (ParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args){
		HtmlProcess htmlprocess = new HtmlProcess();
		htmlprocess.htmlprocess();
	}
	
	
	
}
